<?php
$app = Blyn::app()->getActiveApp();
?>
<?php
if (!isset($model))
    $model = new BDynamicFormModel ();

$categoryNameField = 'media_name_buyer_category';
$categoryAliasField = 'media_alias_buyer_category';
$model->addField($categoryNameField);
$model->addField($categoryAliasField);

$categoryView = array();
if ($buyerId > 0) {
    //first get product
    $buyerTable = new BPSheet('buyer');
    $buyer = $buyerTable->getListById($buyerId);
    $categoryMemberTable = new BPCategorySheet('buyerCategory', $buyer);

    $categoryView = $categoryMemberTable->getView();
}
?>
<?php
$form = $this->beginWidget('CActiveForm', array(
    "id" => "addBuyerCategoryForm",
    'enableAjaxValidation' => FALSE,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
        ));
?>
<div class="well row-fluid">
    <div class="input-prepend">
        <span class="add-on">全名</span>
        <?php
        echo CHtml::activeTextField($model, $categoryNameField, array('placeholder' => 'category Name' . '...', 'required' => true));
        ?>
    </div>
    <div class="input-prepend">
        <span class="add-on">别名</span>
        <?php
        echo CHtml::activeTextField($model, $categoryAliasField, array('placeholder' => 'category alias' . '...', 'required' => true));
        ?>
    </div>
    <div class="input-append">
        <?php
        echo $control->getAjaxLink(array('name' => '添加分类', 'id' => 'addBuyerCategory'), array(
            'htmlOptions' => array('class' => 'btn'),
            'buyerId' => $buyerId));
        ?>
    </div>
</div>
<?php if (count($categoryView) > 0) { ?>
    <div style="min-height: 100px">
        <table class="table table-hover">
            <colgroup>
                <col class="span1">
                <col class="span7">
            </colgroup>
            <thead>
                <tr>
                    <th></th>
                    <th><?php echo '分类全名'; ?></th>
                    <th><?php echo '分类别名'; ?></th>
                </tr>
            </thead>
            <tbody>
                <?php
                foreach ($categoryView as $list) {
                    $categoryName = '';
                    $categoryAlias = '';
                    $categoryIdItem = $list->getItem('categoryId');
                    if ($categoryIdItem instanceof BTreeItem) {
                        $categoryId = $categoryIdItem->getValue();
                        $category = new BPCategory($categoryId);
                        $categoryName = $category->getCategoryFullName();
                        $categoryAlias = $category->getValue();
                    }
                    if ($categoryName != '') {
                        ?>
                        <tr><td><input type="checkbox"></td>
                            <td> <?php
                                echo $categoryName;
                                ?> </td>
                            <td>
                                <?php
                                echo $categoryAlias;
                                ?>
                            </td>
                        </tr>   
                    <?php }
                } ?>
            </tbody>
        </table>
    </div>
<?php } ?>
<?php
$this->endWidget();
//echo CHtml::endForm();
?>



